package com.gitee.neuray.security.mail.rpc;

import com.gitee.neuray.security.common.msg.ObjectRestResponse;
import com.gitee.neuray.security.common.util.EntityUtils;
import com.gitee.neuray.security.mail.biz.MailBiz;
import com.gitee.neuray.security.mail.feign.MailServiceFeignClient;
import com.gitee.neuray.security.mail.vo.SendStausVo;
import com.gitee.neuray.security.mail.vo.SysMailSourceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
 * @auther: zhuqz
 * @date: 2020/2/26 09:39
 * @description:
 */
@RestController
@RequestMapping("api")
public class MailRest  implements MailServiceFeignClient {
    @Autowired
    MailBiz mailBiz;

    //添加邮件
    @Override
    @RequestMapping(value="/mail/addMail",method = RequestMethod.POST)
    public ObjectRestResponse addMail(@RequestBody SysMailSourceVo vo){
        try {

            this.mailBiz.add(vo);
        } catch (Exception e) {
            e.printStackTrace();
            return  new ObjectRestResponse().rel(true).msg("500").data("添加失败");
        }
        return  new ObjectRestResponse().rel(true).msg("200").data("添加成功");
    }

    @Override
    @RequestMapping(value="/mail/sendTimerMail",method = RequestMethod.POST)
    public ObjectRestResponse sendTimerMail() {
        SendStausVo vo = null;
        try {
            vo = this.mailBiz.sendTimerMail();
        } catch (Exception e) {
            e.printStackTrace();
            return  new ObjectRestResponse().rel(false).msg("500").data(vo);
        }
        return  new ObjectRestResponse().rel(true).msg("200").data(vo);
    }
    @Override
    @RequestMapping(value="/mail/addBirthDayTimerMail",method = RequestMethod.POST)
    public ObjectRestResponse addBirthDayTimerMail() {
        int res = 1;
        try {
            res = this.mailBiz.addBirthdayTimerMail();
        } catch (Exception e) {
            e.printStackTrace();
            return  new ObjectRestResponse().rel(false).msg("500").data(res);
        }
        return  new ObjectRestResponse().rel(true).msg("200").data(res);
    }
}